package com.sumainfor.wx.tenant.controller.gmio;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.wx.tenant.service.impl.GmioFeign.TenantCouService;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 功能描述:
 * 运营部-优惠券
 *
 * @Auther: zhlu
 * @Date: 2019/4/7 16:25
 * @Description:
 */
@RestController
@RequestMapping("/key/coupons")
public class TenantCouController {

    @Autowired
    TenantCouService TenantCouService;

    /**
     * 功能描述:
     * 根据优惠券编号和租客编号获取当前优惠券是否是当前租客的
     *
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/7 16:28
     */
    @GetMapping("/getTenantCouCount")
    public JsonResult getTenantCouCount(@RequestParam Map<String, Object> params) {
        JsonResult result = new JsonResult();
        if (!FieldCheckUtil.isMapFieldNotNull(params, new String[]{"CouId"})) {
            result.putFailed("CouId不能为空！");
            return result;
        }
        if (!FieldCheckUtil.isMapFieldNotNull(params, new String[]{"TenId"})) {
            result.putFailed("TenId不能为空！");
            return result;
        }
        result.put(TenantCouService.getTenantCouCount(params));
        return result;
    }

    /**
     * 功能描述:
     * 根据优惠券编号和租客修改优惠券已使用
     *
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/7 16:30
     */
    @PostMapping("/UpdateTenantCou")
    public JsonResult UpdateTenantCou(@RequestBody Map<String, Object> params) {
        JsonResult result = new JsonResult();
        if (TenantCouService.UpdateTenantCou(params)) {
            result.putSuccess("修改成功！");
        } else {
            result.putFailed("服务器繁忙，请稍后重试！");
        }
        return result;
    }

    /**
     * 查询获取用户信息数据
     *
     * @param params
     * @return
     */
    @PostMapping("/selectTenantTableList")
    public Page<Map<String, Object>> selectTenantTableList(@RequestParam Map<String, Object> params) {
        Page page = new Page(MapUtils.getLongValue(params, "current"), MapUtils.getLongValue(params, "size"));
        return TenantCouService.selectTenantTableList(page, MapUtils.getString(params, "search"));
    }

    /**
     * 根据租客编号查询手机号
     * @param params
     * @return
     */
    @PostMapping("/getTenPhone")
    public JsonResult getTenPhone(@RequestBody Map<String,Object> params){
        JsonResult result = new JsonResult();
        return result.put(TenantCouService.getTenPhone(params));
    }



}
